//#ifndef outstream_js
//#define outstream_js 1

//#include "encode.js"

// Used to write values represented by a user specified number of 
// bits into a 'bytestream' array.

function OutStream() {
  this.bytestream = [];
  this.offset = 0;
}

OutStream.prototype = {

  WriteBit : function(val) {
    this.bytestream[this.offset>>>3] |= val << (this.offset & 7);
    this.offset++;
  },

  Write : function(val, numBits) {
    // Write LSB -> MSB
    for(var i = 0; i < numBits; ++i) {
      this.WriteBit((val >>> i) & 1);
    }
  },
  
  toString : function() {
    return encode.fromNumber(this.offset)
      +'!'+encode.fromArray(this.bytestream);
  }

}

//#endif

